"""  
       @File     : 获取csv2.py
       @IDE      : PyCharm
       @Author   : 陈引弟
       @Date     : 2025/3/13 15:31
       @Desc     : 
=========================================================   
"""
import pandas as pd

def generate_city_csv(city_name):
    df = pd.read_csv(r'F:\python\基于大数据的天气预测分析系统\model\lishiweather.csv')
    filtered_data = df[df['city'] == city_name][['date', 'mastHeightDay','mastSmallDay']]
    filtered_data.rename(columns={'date': 'Date', 'mastHeightDay': 'Temp1','mastSmallDay':'Temp2'}, inplace=True)
    filtered_data['Date'] = pd.to_datetime(filtered_data['Date'])
    filtered_data.sort_values(by='Date', inplace=True)
    filtered_data.to_csv(r'F:\python\基于大数据的天气预测分析系统\model\weather1.csv', index=False)
    return True

# import pandas as pd
# #
# # # 指定要提取的城市
# target_city = "七台河"
#
# # 读取原始数据
# df = pd.read_csv(r'F:\python\基于大数据的天气预测分析系统2\model\lishiweather.csv')
#
# # 筛选指定城市的数据
# filtered_data = df[df['city'] == target_city][['date', 'mastHeightDay','mastSmallDay']]
#
# # 修改列名
# filtered_data.rename(columns={'date': 'Date', 'mastHeightDay': 'Temp1', 'mastSmallDay':'Temp2'}, inplace=True)
#
# # 将 'Date' 列转换为日期时间格式
# filtered_data['Date'] = pd.to_datetime(filtered_data['Date'])
#
# # 按 'Date' 列排序
# filtered_data.sort_values(by='Date', inplace=True)
#
# # 保存到新的 CSV 文件
# filtered_data.to_csv(r'F:\python\基于大数据的天气预测分析系统2\model\weather1.csv', index=False)
#
# print("数据提取完成，已生成新的 CSV 文件")